package com.xrit.sunnyday.job;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.service.SetmealService;
import com.xrit.sunnyday.utils.QiNiuUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 任务调度类
 */
@Component("cleanImgJob")
public class CleanImgJob {

    /**
     * 订阅服务
     */
    @Reference
    private SetmealService setmealService;

    public void cleanImg(){
        // 1.查出7牛上的所有图片
        List<String> imgIn7Niuyun = QiNiuUtils.listFile();
        // 2.查出数据库中的所有图片
        List<String> imgInDb = setmealService.findImgs();
        // 3.7牛的图片减数据库套餐表
        imgIn7Niuyun.removeAll(imgInDb);
        // 5.现在7牛云只剩下垃圾图片，将List转成String数组
        String[] strings = imgIn7Niuyun.toArray(new String[]{});
        //4.调用7牛云的删除方法
        QiNiuUtils.removeFiles(strings);
    }
}
